package com.amc.utils;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class HttpConnUtil {
	//获取连接
	public static HttpURLConnection getConnection(String urlPath, String method) {
		HttpURLConnection conn = null;
		try {
			URL url = new URL(urlPath);
			conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod(method);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static String show(HttpURLConnection conn) {
		String result = "";
		try {
			conn.connect();
			int resCode = conn.getResponseCode();
			if(resCode == 200){
				InputStream is = conn.getInputStream();
				BufferedReader br = new BufferedReader(new InputStreamReader(is));
				String line = "";
				while((line = br.readLine()) != null){
					result += line;
				}
				System.out.println("[result] : " + result);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

}
